package com.itheima.hotel;

import java.util.Scanner;

public class Test {

    public static final Hotel hotel = new Hotel();

    public static void main(String[] args) {

        // 系统入口
        while (true) {
            final Scanner sc = new Scanner(System.in);
            System.out.println("----------酒店管理系统-----------");
            System.out.println("请输入用户和密码登录系统. ");
            System.out.println("请输入用户名: ");
            final String username = sc.next();
            System.out.println("请输入密码: ");
            final String password = sc.next();

            // 检查登录
            hotel.login(username, password);

            if (hotel.isHas_login()) {
                showMenu();
            }
        }
    }

    public static void showMenu() {
        while (true) {
            System.out.println("欢迎使用酒店管理系统！");
            System.out.println("1. 查询所有房间信息");
            System.out.println("2. 预订房间");
            System.out.println("3. 退订房间");
            System.out.println("4. 查看已预订房间");
            System.out.println("5. 退出系统");

            final Scanner sc = new Scanner(System.in);
            final String command = sc.next();

            switch (command) {
                case "1":
                    queryRooms();
                    break;
                case "2":
                    bookingRoom();
                    break;
                case "3":
                    cancelRoom();
                    break;
                case "4":
                    hotel.displayAllReservedRooms();
                    break;
                case "5":
                    hotel.setHas_login(false);
                    return;
                default:
                    System.out.println("输入有误，请重试.");
            }
        }
    }

    // 查询房间
    public static void queryRooms() {
        System.out.println("----------查询房间----------");
        System.out.println("1. 按房间类型排序查询. ");
        System.out.println("2. 按房间编号排序查询. ");
        final Scanner sc = new Scanner(System.in);
        final String command = sc.next();
        switch (command) {
            case "1" -> hotel.sortRoomsByType();
            case "2" -> hotel.sortRoomsByNumber();
            default -> System.out.println("输入有误！");
        }
    }

    // 预定房间
    public static void bookingRoom() {
        final Scanner sc = new Scanner(System.in);

        System.out.println("----------预定房间----------");
        System.out.println("请输入房间类型< 1. 单人间 > < 2. 双人间 >: ");
        final String roomType = sc.next();
        if (!roomType.equals("1") && !roomType.equals("2")) {
            System.out.println("房间类型不存在！");
            return;
        }

        System.out.println("请输入入住时间: ");
        final String checkInDate = sc.next();

        hotel.reserveRoom(roomType, checkInDate);
    }

    // 退订房间
    public static void cancelRoom() {
        final Scanner sc = new Scanner(System.in);

        System.out.println("----------退订房间----------");
        System.out.println("请输入订单号: ");
        final String orderNumber = sc.next();

        hotel.cancelReservation(orderNumber);
    }
}
